package com.flash.mapper;

import com.github.pagehelper.Page;
import com.flash.annotation.AutoFill;
import com.flash.dto.DishPageQueryDTO;
import com.flash.entity.Dish;
import com.flash.enumeration.OperationType;
import com.flash.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {


    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId} ")
    Integer countByCategoryId(@Param("categoryId") Long categoryId);

    /**
     * 添加菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 检查不能被删除的菜品个数
     * @param ids
     * @return
     */
    int couldNotBeDeleted(List<Long> ids);

    /**
     * 删除列表中的菜品
     * @param ids
     */
    void deleteById(List<Long> ids);

    /**
     * 通过id获取数据
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id} ")
    Dish selectById(Long id);

    /**
     * 更新菜品数据
     * @param dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 更新菜品状态
     * @param status
     * @param id
     */
    @Update("update dish set status = #{status} where id = #{id}")
    void updateDishStatus(Integer status, Long id);
    @Select("select * from setmeal where id = #{id}")
    List<Dish> getBySetMealId(Long id);

    List<Dish> getDishByCategory(Long categoryId);

    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);


}
